<?php
namespace app\common\tool;
use think\Model;
class Upload extends Model
{
	public function upload($imgName, $who, $thumb=[])
	{
		$file = request()->file($imgName);
		$filename = $imgName . '_'.$who.'_'. '1';
		$filePath = config($who.'_img_path');
		$info = $file->move($filePath, $filename);
		if($info){
			$ret['images'][0] = $info->getFilename();
			if($thumb)
			{
				foreach($thumb as $k => $v)
				{
				
					$ret['images'][$k+1] = $filePath . DS . $imgName . '_'.$v[0].'_'. $v[1].'_'.$who.'_'. '1' . '.' . $info->getExtension();
					$img = $filePath . DS . $info->getFilename();
					// halt($thumbImg);
					$image = \think\Image::open($img);
					$image->thumb($v[0], $v[1], \think\Image::THUMB_FIXED)->save($ret['images'][$k+1]);
				}
			}
		}else{
		// 上传失败获取错误信息
			return returnJson([0, $file->getError()]);
		}

		return $ret;
	}  

}